package com.snail.common.dyd;


import com.snail.common.dyd.bean.DataSourceInfo;

/**
 * 动态数据源切换处理类
 */
public abstract class AbstractDynamicDataBaseProcessor {


    private DataBaseOperatorProvider dataBaseOperatorProvider;

    private DataSourceSwitcher dataSourceSwitcher;

    private DataBaseTypeSwitcher dataBaseTypeSwitcher;

    private DataSourceIdProvider dataSourceIdProvider;


    private DataSourceInfoProvider dataSourceInfoProvider;

    public void switchDataBase() {

        // 1.获取数据源信息
        DataSourceInfo dataSourceInfo = dataSourceInfoProvider.getDataSourceInfo(dataSourceIdProvider.getDataSourceId());

        // 2.切换数据源
        dataSourceSwitcher.switchDataSource(dataSourceInfo);

        // 3.切换数据库类型操作者
        dataBaseTypeSwitcher.switchDataBaseType(dataBaseOperatorProvider.getDataBaseOperator(dataSourceInfo.getDbType()));
    }



}
